package com.dfec.book.controller;


import com.dfec.book.service.BookStatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dfec.book.util.AjaxResult;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author tangrg
 * @email 1446232546@qq.com
 * @date 2025-06-2025/6/20 14:38:16
 */
@RestController
@RequestMapping("/book/stat")
@Api(tags = "图书统计接口", description = "提供图书管理系统的各类统计功能")
public class BookStatController {

    @Resource
    private BookStatService statisticsService;

    /**
     * 获取图书基本信息统计
     */
    @GetMapping("/bookInfoDatas")
    @ApiOperation(value = "图书信息统计",
            notes = "获取图书基本信息统计数据，包括各类图书数量、状态等",
            response = AjaxResult.class)
    public AjaxResult<List<Map<String, Object>>> bookInfoDatas() {
        try {
            List<Map<String, Object>> data = statisticsService.bookInfoDatas();
            return AjaxResult.ok(data);
        } catch (Exception e) {
            return AjaxResult.error("获取图书信息统计失败: " + e.getMessage());
        }
    }

    /**
     * 获取图书借阅信息统计
     */
    @GetMapping("/borrowingInfoDatas")
    @ApiOperation(value = "借阅信息统计",
            notes = "获取图书借阅情况统计数据，包括借阅量、归还率等",
            response = AjaxResult.class)
    public AjaxResult<List<Map<String, Object>>> borrowingInfoDatas() {
        try {
            List<Map<String, Object>> data = statisticsService.borrowingInfoDatas();
            return AjaxResult.ok(data);
        } catch (Exception e) {
            return AjaxResult.error("获取借阅信息统计失败: " + e.getMessage());
        }
    }

    /**
     * 获取图书分类借阅TOP统计
     */
    @GetMapping("/categoryBorrowingDatas")
    @ApiOperation(value = "分类借阅TOP",
            notes = "获取各类图书借阅量排名TOP10",
            response = AjaxResult.class)
    public AjaxResult<List<Map<String, Object>>> categoryBorrowingDatas() {
        try {
            List<Map<String, Object>> data = statisticsService.categoryBorrowingDatas();
            return AjaxResult.ok(data);
        } catch (Exception e) {
            return AjaxResult.error("获取分类借阅TOP失败: " + e.getMessage());
        }
    }

    /**
     * 获取图书借阅TOP统计
     */
    @GetMapping("/bookBorrowingDatas")
    @ApiOperation(value = "图书借阅TOP",
            notes = "获取最受欢迎图书借阅量排名TOP10",
            response = AjaxResult.class)
    public AjaxResult<List<Map<String, Object>>> bookBorrowingDatas() {
        try {
            List<Map<String, Object>> data = statisticsService.bookBorrowingDatas();
            return AjaxResult.ok(data);
        } catch (Exception e) {
            return AjaxResult.error("获取图书借阅TOP失败: " + e.getMessage());
        }
    }

    /**
     * 获取读者借阅TOP统计
     */
    @GetMapping("/userBookBorrowingDatas")
    @ApiOperation(value = "读者借阅TOP",
            notes = "获取读者借阅量排名TOP10",
            response = AjaxResult.class)
    public AjaxResult<List<Map<String, Object>>> userBookBorrowingDatas() {
        try {
            List<Map<String, Object>> data = statisticsService.userBookBorrowingDatas();
            return AjaxResult.ok(data);
        } catch (Exception e) {
            return AjaxResult.error("获取读者借阅TOP失败: " + e.getMessage());
        }
    }
}